package com.pandy.leetcode.daily;

/**
 * @description: 每日一题
 *字母在字符串中的百分比
 * https://leetcode.cn/problems/percentage-of-letter-in-string/description
 * @author: panhong
 * @date: 2025/3/31
 */
public class Code001_String_PercentageLetter {

    public static int percentageLetter(String s, char letter) {
        if(s == null || s.isEmpty()) {
            return 0;
        }

        int size = 0;
        char[] charArray = s.toCharArray();
        for(int i=0; i< charArray.length; i++) {
            if(letter == charArray[i]) {
                size ++;
            }
        }

        return  size == 0 ? 0 : size * 100 / charArray.length;
    }

    public static void main(String[] args) {
        System.out.println(percentageLetter("jjjj",'j'));
    }
}
